<!--首页-->
<template>
  <div>
    <Head :user="user" :newMessageNum="newMessageNum" :newCommentNum="newCommentNum"></Head>
    <router-view></router-view>
  </div>
</template>

<script>
import Head from '../base/Head'
import IndexContent from './IndexContentHot'
import Adaption from '../base/Adaption'

export default {
  name: 'Index',
  data () {
    return {
      newMessageNum: 0,
      newCommentNum: 0,
      // isLogin不可存入vue实例中，此处为测试值
      // 应当直接从后端获取isLogin
      user: {
        id: '',
        headPhoto: ''
      }
    }
  },
  components: {Adaption, Head, IndexContent},
  mounted () {
    // 获取当前客户端状态及其登录的userId
    this.axios.get('/user/getUser').then(function (res) {
      if (res.data.result) {
        // 渲染小红点
        this.newMessageNum = 5
        this.newCommentNum = 8
        // 头部栏用户头像id数据渲染
        this.user.id = res.data.result.id
        this.axios.get('/user/queryUserHeadById', {
          params: {
            uid: this.user.id
          }
        }).then(function (res) {
          // 头部栏用户头像渲染
          this.user.headPhoto = '/static/head-photo/' + res.data.result
        }.bind(this))
      }
    }.bind(this))
  }
}
</script>

<style scoped>

</style>
